package com.xhldtc.proxy;

import java.io.IOException;

import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class Test
{
	public static void main(String[] args) throws ClientProtocolException,
			IOException
	{
//		System.setProperty("http.proxyHost", "10.240.45.225");
//		System.setProperty("http.proxyPort", "80");

		DefaultHttpClient client = new DefaultHttpClient();
		
		HttpHost proxy = new HttpHost("10.240.45.225",80);
		client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
		
		
		HttpGet hg = new HttpGet("http://www.google.com");

		// HttpPost hp = new HttpPost("http://localhost:8080/proxy/main");
		// HttpParams hp = new BasicHttpParams();
		// hp.setParameter("hello", "world");
		// hg.setParams(hp);
		// 此处httpParams不同于get方法的parameter,不必要设置

		System.out.println("Begin...");
		HttpResponse response = client.execute(hg);
		System.out.println(EntityUtils.toString(response.getEntity()));
	}

}
